package com.briup.cms.util;

import lombok.Data;

import java.util.Date;

@Data
public class  Result<T> {
    private Integer code;
    private String message;
    private long date;
    private T data;
    public Result(StatusCode statusCode,T data) {
        this.code = statusCode.getCode();
        this.message = statusCode.getMessage();
        date = new Date().getTime();
        this.data = data;
    }

    public Result(StatusCode statusCode) {
        this(statusCode,null);
    }

    public static <E> Result<E> success(E data) {
        Result<E> result = new Result<>(StatusCode.SUCCESS,data);
        return result;
    }


    public static Result success() {
        Result result = new Result<>(StatusCode.SUCCESS,null);
        return result;
    }


    public static <E> Result<E> fail(StatusCode statusCode,E data) {
        Result<E> result = new Result<>(statusCode,data);
        return result;
    }


    public static Result fail(StatusCode statusCode) {
        Result result = new Result<>(statusCode,null);
        return result;
    }
}
